package com.suixinsanren.design.template.demo07;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public abstract class CaffeineBeverage {

    protected void prepareRecipe() {
        boilWater();
        brew();
        pourInCup();
        if (customerWantsCondiments()) {
            addCondiments();
        }
    }

    abstract void addCondiments();

    abstract void brew();

    abstract void askCustomer();

    protected void boilWater() {
        System.out.println("烧开水");
    }

    protected void pourInCup() {
        System.out.println("倒入杯子");
    }

    protected boolean customerWantsCondiments() {
        return getUserInput().startsWith("y");
    }

    protected String getUserInput() {
        askCustomer();
        String answer = null;
        try {
            answer = new BufferedReader(new InputStreamReader(System.in)).readLine();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("读取用户输入失败");
        }
        return answer == null ? "no" : "yes";
    }
}
